home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lcppb.zip / LCPP08.ZIP / RDATA.CPP < prev    next >
C/C++ Source or Header  |  1991-07-08  |  1KB  |  46 lines

  1. // rdata.cpp -- Read data file
  2.  
  3. //#include <stream.hpp>
  4. #include <iostream.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. #define MAX 100   // Number of values to write
  9.  
  10. void error(const char *s);
  11.  
  12. main()
  13. {
  14.   double fpArray[MAX];
  15.   int i, n;
  16.   FILE *fp;
  17.  
  18.   fp = fopen("TEST.DAT", "rb");
  19.   if (fp == NULL) error("Can't open TEST.DAT");
  20.   cout << "Reading array from TEST.DAT...\n";
  21.   for (i = 0; i < MAX; i++) {
  22.     if feof(fp) error("Unexpected end of file");
  23.     n = fread(&fpArray[i], sizeof(double), 1, fp);
  24.     if (n != 1) error("Reading data");
  25.   }
  26.   fclose(fp);
  27.   cout << "\nValues read from disk:\n";
  28.   for (i = 0; i < MAX; i++)
  29. //    cout << form("%16.8f", fpArray[i]);
  30.     printf("%16.8f", fpArray[i]);
  31. }
  32.  
  33. void error(const char *s)
  34. {
  35.   cout << "\nERROR: " << s;
  36.   exit(1);
  37. }
  38.  
  39.  
  40. // Copyright (c) 1990 by Tom Swan. All rights reserved
  41. // Revision 1.00    Date: 11/11/1990   Time: 09:11 am
  42.  
  43. // Revision 1.01    Date: 07/08/1991   Time: 05:41 pm
  44. // Converted for Borland C++ 2.0
  45.  
  46.